﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>配置文件内容展示</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <style type="text/css">
        .ccup, .ccdown {
            cursor: pointer;
        }

        .opFly {
            position: absolute;
            z-index: 999;
            border-style: solid;
            border-left-color: #eef7fd;
            border-top-color: #eef7fd;
            border-right-color: #d3e9fc;
            border-bottom-color: #d3e9fc;
            background-color: #deeffc;
        }

        .layui-table {
            margin: 0 0;
        }

        .layui-tab-content {
            padding-top: 0;
        }

        .ew-tree-table .ew-tree-table-tool {
            padding: 10px;
            line-height: 0;
        }

        #opToolBarForm .layui-form-item {
            margin-bottom: 0;
        }
        .unoperate {
            display: none;
        }
    </style>
</head>
<body>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" id="processTab" lay-filter="processTab">
                <input type="hidden" id="processType" />
                <ul class="layui-tab-title">
                    <li class="layui-this" lay-id="analysis">分析流程</li>
                    <li lay-id="optimize">优选流程</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <table class="layui-table" id="analysisTable" lay-filter="analysisTable"></table>
                    </div>
                    <div class="layui-tab-item">
                        <table class="layui-table" id="optimizeTable" lay-filter="optimizeTable"></table>
                    </div>
                </div>
            </div>
        </div>

    </div>


    <script type="text/html" id="ananlysisToolBar">
        <a href="javascript:;" class="layui-btn operateBtn unoperate" lay-event="addItem">
            <i class="layui-icon"></i>添加步骤
        </a>
    </script>
    <script type="text/html" id="optimizeToolBar">
        <form class="layiu-form" id="opToolBarForm">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <a href="javascript:;" class="layui-btn operateBtn unoperate" lay-event="addItem">
                        <i class="layui-icon"></i>添加步骤
                    </a>
                </div>
                <div class="layui-input-inline">
                    <select name="stepType" id="stepType">
                        <option value="1">分组模块</option>
                        <option value="2" selected="selected">普通模块</option>
                    </select>
                </div>
            </div>

        </form>

    </script>

    <script src="../lib/layui/layui.js"></script>
    <script type="text/html" id="barhand">
        {{# if(d.stepType=="1"){ }}
        <a title="添加" class="operateBtn unoperate" href="javascript:;" lay-event="addSubItem">
            <i class="layui-icon">&#xe63c;</i>添加
        </a>
        {{# } }}
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm ccup operateBtn unoperate" lay-event="moveup">上移</button>
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm ccdown operateBtn unoperate" lay-event="movedown">下移</button>
        <a title="删除" href="javascript:;" lay-event="del" class="operateBtn unoperate">
            <i class="layui-icon">&#xe640;</i>删除
        </a>



    </script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    var arr, reg = new RegExp("(^| )" + strs[i].split("=")[0] + "=([^;]*)(;|$)");
                    if (arr = strs[i].match(reg))
                        theRequest[strs[i].split("=")[0]] = unescape(arr[2]);
                    /* theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);*/
                }
            }
            return theRequest;
        };
        //var fileName = JSON.parse(window.decodeURIComponent(atob(getrequest().fileName)))
        var fileName = getrequest().fileName;
        layui.config({
            base: "/lib/layui/lay/plugins/"
        }).extend({
            treeTable: "treeTable/treeTable"
        }).use(['table', 'element', 'treeTable'], function () {
            var table = layui.table;
            var element = layui.element;
            var treeTable = layui.treeTable;
            var $ = layui.$;
            var isOperate = 0;
            element.render();
            //$("#processTab >li[lay-id='optimize']").click();
            element.tabChange('processTab', 'analysis');
            $("#processType").val("analysis");
            loadAnalysis();
            element.on('tab(processTab)', function (el) {
                var type = $(this).attr("lay-id");
                $("#processType").val(type);
                if (type == "analysis") {
                    loadAnalysis();
                }
                else if (type == "optimize") {
                    loadOptimize();
                }
            });

            //表头部工具栏事件
            table.on('toolbar(analysisTable)', function (obj) {
                switch (obj.event) {
                    case 'addItem':
                        layer.open({
                            type: 2,
                            title: '添加配置项',
                            maxmin: true,
                            shadeClose: true,
                            area: ['600px', '480px'],
                            content: 'addItems.html' + '?fileName=' + fileName + '&processType=analysis',
                            end: function () {
                                table.reload("analysisTable");
                            }
                        });
                        break;
                }
            });

            treeTable.on('toolbar(optimizeTable)', function (obj) {
                switch (obj.event) {
                    case 'addItem':
                        var stepType = layui.$("#stepType").val();
                        if (stepType == "1") {
                            layer.open({
                                type: 2,
                                title: '分组配置项',
                                maxmin: true,
                                shadeClose: true,
                                area: ['600px', '350px'],
                                content: 'addGroupItems.html' + '?fileName=' + fileName + '&processType=optimize',
                                end: function () {
                                    treeTable.reload("optimizeTable");
                                }
                            });

                        } else if (stepType == "2") {
                            layer.open({
                                type: 2,
                                title: '添加配置项',
                                maxmin: true,
                                shadeClose: true,
                                area: ['600px', '480px'],
                                content: 'addItems.html' + '?fileName=' + fileName + '&processType=optimize',
                                end: function () {
                                    treeTable.reload("optimizeTable");
                                }
                            });
                        }
                        break;
                }
            })

            //监听行工具事件
            table.on('tool(analysisTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var d = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr;//获得当前行 tr 的 DOM 对象
                switch (layEvent) {
                    case 'moveup':
                        layer.msg('上移');
                        moveUp(d, "analysis");
                        break;
                    case 'movedown':
                        layer.msg('下移');
                        moveDown(d, "analysis");
                        break;
                    case 'del':
                        layer.msg('删除');
                        //删除流程
                        member_del(d, "analysis");
                        break;
                    default:
                }
            });
            treeTable.on('tool(optimizeTable)', function (obj) {
                var d = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr;//获得当前行 tr 的 DOM 对象
                var groupStepCode = d.code;
                switch (layEvent) {
                    case 'moveup':
                        layer.msg('上移');
                        moveUp(d, "optimize");
                        break;
                    case 'movedown':
                        layer.msg('下移');
                        moveDown(d, "optimize");
                        break;
                    case 'del':
                        layer.msg('删除');
                        //删除模块
                        member_del(d, "optimize");
                        break;
                    case 'addSubItem':
                        layer.open({
                            type: 2,
                            title: '添加配置项',
                            maxmin: true,
                            shadeClose: true,
                            area: ['600px', '480px'],
                            content: 'addItems.html' + '?fileName=' + fileName + '&processType=optimize&groupStepCode=' + groupStepCode + ''
                        });
                        break;
                    default:
                        break;
                }
            })


            //加载分析流程配置
            function loadAnalysis() {
                table.render({
                    elem: '#analysisTable'
                    , method: 'get'
                    , skin: 'row'
                    , toolbar: '#ananlysisToolBar'
                    , even: true
                    , page: false
                    , headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    }
                    , url: localStorage.getItem('hosttingaddr') + '/Manager/ProcessCfgFile/analysisdetail' //数据接口
                    , cols: [[ //表头
                        { field: 'number', title: '步骤序号',with:25, align: 'center' }
                        , { field: 'executeFile', title: '配置文件', align: 'center' }
                        , { field: 'executeType', title: '执行类型', align: 'center' }
                        , { field: 'executeCode', title: '执行代码', align: 'center' }
                        , { field: 'code', title: '步骤编码', align: 'center' }
                        , { field: 'zh_cn', title: '备注信息', align: 'center' }
                        , { fixed: 'right', title: "操作", align: 'center', toolbar: '#barhand' }
                    ]]
                    , done: function (res) {
                        isOperate = res.isOperate;
                        if (res.isOperate != 1) {
                            layui.$(".operateBtn").addClass("unoperate");
                        }
                        else {
                            layui.$(".operateBtn").removeClass("unoperate");
                        }
                    }
                    , where: getWhere()

                });
            }

            //加载优选流程配置
            function loadOptimize() {
                treeTable.render({
                    elem: '#optimizeTable'
                    , method: 'get'
                    , skin: 'row'
                    , toolbar: '#optimizeToolBar'
                    , tree: {
                        iconIndex: 0,
                        isPidData: true,
                        idName: 'code',
                        pidName: 'groupStepCode',
                        getIcon: function (d) {  // 自定义图标
                            // d是当前行的数据
                            if (d.haveChild) {  // 判断是否有子集
                                return '<i class="ew-tree-icon ew-tree-icon-folder"></i>';
                            } else {
                                return '<i class="ew-tree-icon"></i>';
                            }
                        }
                    }
                    , page: false
                    , headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    }
                    , url: localStorage.getItem('hosttingaddr') + '/Manager/ProcessCfgFile/optimizedetail' //数据接口
                    , cols: [[ //表头
                        { field: 'number', title: '步骤序号', with: 25, align: 'center' }
                        , { field: 'executeFile', title: '配置文件', align: 'center' }
                        , { field: 'executeType', title: '执行类型', align: 'center' }
                        , { field: 'executeCode', title: '执行代码', align: 'center' }
                        , { field: 'code', title: '步骤编码', align: 'center' }
                        , { field: 'zh_cn', title: '备注信息', align: 'center' }
                        , { fixed: 'right', title: "操作", align: 'center', toolbar: '#barhand' }
                    ]]
                    , done: function (res) {
                        if (isOperate != 1) {
                            layui.$(".operateBtn").addClass("unoperate");
                        }
                        else {
                            layui.$(".operateBtn").removeClass("unoperate");
                        }
                    }
                    , where: getWhere()

                });
            }

            function getWhere() {
                var where = {};
                where.fileName = fileName;
                return where;
            }
            function moveUp(d, processType) {
                $ = layui.$;
                var url = "";
                var data = {};
                if (d.stepType == "1") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/movegroupitem";
                    data = {
                        fileName: fileName,
                        processType: processType,
                        groupCode: d.code,
                        operateFlag: "1"
                    }
                } else if (d.stepType == "2") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/moveitem";
                    data = {
                        fileName: fileName,
                        processType: processType,
                        groupCode: d.groupStepCode,
                        current: d.number,
                        operateFlag: "1"
                    }
                }
                layer.confirm('确认要上移吗？', function (index) {
                    //发异步删除数据
                    layui.$.ajax({
                        type: "post",
                        url: url,
                        headers: {
                            user: getCookie("userinfo"),
                            version: getCookie("version")
                        },
                        data: data,
                        //dataType:"json",
                        success: function (data) {
                            layer.msg(data.msg, { icon: 1, time: 1000 });
                            if (processType == "analysis") {
                                table.reload("analysisTable");
                            }
                            else if (processType == "optimize") {
                                treeTable.reload("optimizeTable");
                            }
                        }
                    });

                });
            }
            // 下移
            function moveDown(d, processType) {
                $ = layui.$;
                var url = "";
                var data = {};
                if (d.stepType == "1") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/movegroupitem";
                    data = {
                        fileName: fileName,
                        processType: processType,
                        groupCode: d.code,
                        operateFlag: "2"
                    }
                } else if (d.stepType == "2") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/moveitem";
                    data = {
                        fileName: fileName,
                        processType: processType,
                        groupCode: d.groupStepCode,
                        current: d.number,
                        operateFlag: "2"
                    }
                }
                layer.confirm('确认要下移吗？', function (index) {
                    //发异步删除数据
                    layui.$.ajax({
                        type: "post",
                        url: url,
                        headers: {
                            user: getCookie("userinfo"),
                            version: getCookie("version")
                        },
                        data: data,
                        //dataType:"json",
                        success: function (data) {
                            layer.msg(data.msg, { icon: 1, time: 1000 });
                            if (processType == "analysis") {
                                table.reload("analysisTable");
                            }
                            else if (processType == "optimize") {
                                treeTable.reload("optimizeTable");
                            }
                        }
                    });

                });

            }
            // 删除文件
            function member_del(d, processType) {
                var url = "";
                var data = {};
                if (d.stepType == "1") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/deletegroupitem";
                    data = {
                        fileName: fileName,
                        processType: processType,
                        groupCode: d.code,
                    };
                }
                else if (d.stepType == "2") {
                    url = localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/deleteitem";
                    data = {
                        fileName: fileName,
                        number: d.number,
                        processType: processType,
                        groupCode: d.groupStepCode
                    };
                }
                layer.confirm('确认要删除吗？', function (index) {
                    //删除数据
                    layui.$.ajax({
                        type: "post",
                        url: url,
                        headers: {
                            user: getCookie("userinfo"),
                            version: getCookie("version")
                        },
                        data: data,
                        success: function (data) {
                            if (processType == "analysis") {
                                table.reload("analysisTable");
                            }
                            else if (processType == "optimize") {
                                treeTable.reload("optimizeTable");
                            }
                            layer.msg(data.msg, { icon: 1, time: 1000 });
                            layer.close(index);
                        }
                    });

                });
            }
            // 添加配置项
            function addItem(obj) {
                layer.open({
                    type: 2,
                    title: '添加配置项',
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '480px'],
                    content: 'addItems.html' + '?fileName=' + fileName
                });
            }

        });
    </script>
</body>
</html>